package com.vito.dcs.roller.statistics.action;

import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.dubbo.config.annotation.Reference;
import com.vito.base.authoriza.action.BaseAction;
import com.vito.base.model.DataGrid;
import com.vito.base.model.ResMsg;
import com.vito.base.model.Result;
import com.vito.dcs.roller.statistics.model.RollerStatisticsModel;
import com.vito.dcs.roller.statistics.service.RollerStatisticsService;

@Controller
@RequestMapping("/roller/statistics")
public class RollerStatisticsAction extends BaseAction{

	private static final Logger log = LoggerFactory.getLogger(RollerStatisticsAction.class);
	
	@Reference
	private RollerStatisticsService rollerStatisticsService;
	
	@RequestMapping("/saveRollerStatistics")
	@ResponseBody
	public Result saveRollerStatistics(@RequestBody List<RollerStatisticsModel> rollerStatisticsModel){
		Result res = new Result();
		try {
			rollerStatisticsService.saveRollerStatistics(rollerStatisticsModel);
			res.setCode(Result.CODE_OK);
			res.setMsg(ResMsg.SAVESUC);
		} catch (Exception e) {
			log.error(ResMsg.SAVEERR, e);
			res.setCode(Result.CODE_ERROR);
			res.setMsg(ResMsg.SAVEERR);
		}
		return res;
	}
	@RequestMapping("/deleteRollerStatistics")
	@ResponseBody
	public Result deleteRollerStatistics(RollerStatisticsModel rollerStatisticsModel){
		Result res = new Result();
		try {
			rollerStatisticsService.deleteRollerStatistics(rollerStatisticsModel);
			res.setCode(Result.CODE_OK);
			res.setMsg(ResMsg.DELSUC);
		} catch (Exception e) {
			log.error(ResMsg.DELERR, e);
			res.setCode(Result.CODE_ERROR);
			res.setMsg(ResMsg.DELERR);
		}
		return res;
	}
	@RequestMapping("/queryRollerStatisticsByPage")
	@ResponseBody
	public Result queryRollerStatisticsByPage(RollerStatisticsModel rollerStatisticsModel){
		Result res = new Result();
		try {
			DataGrid<RollerStatisticsModel> queryRollerStatisticsByPage = rollerStatisticsService.queryRollerStatisticsByPage(rollerStatisticsModel);
			res.setCode(Result.CODE_OK);
			res.setData(queryRollerStatisticsByPage);
		} catch (Exception e) {
			log.error(ResMsg.EXECERR, e);
			res.setCode(Result.CODE_ERROR);
			res.setMsg(ResMsg.EXECERR);
		}
		return res;
	}
	@RequestMapping("/queryRollerNumber")
	@ResponseBody
	public Result queryRollerNumber(@RequestParam Map<String,Object> map){
		Result res = new Result();
		try {
			Map<String, Object> queryRollerNumber = rollerStatisticsService.queryRollerNumber(map);
			res.setCode(Result.CODE_OK);
			res.setData(queryRollerNumber);
		} catch (Exception e) {
			log.error(ResMsg.EXECERR, e);
			res.setCode(Result.CODE_ERROR);
			res.setMsg(ResMsg.EXECERR);
		}
		return res;
	}
	
	
}
